<?php
/**
 * SocialEnginePro
 *
 * @category   Application_Extensions
 * @package    tv
 * @author     Azim
 */

/**
 * @category   Application_Extensions
 * @package    tv
 */
class Tv_AdminManageController extends Core_Controller_Action_Admin
{

  public function indexAction()
  {
    $this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')
      ->getNavigation('tv_admin_main', array(), 'tv_admin_main_manage');

    // Filter form
        $title = $this->_getParam('title');
        $order = $this->_getParam('order');

        $this->view->form = $form = new Tv_Form_Admin_Search();
        if(!empty($title)){
            $form->populate(array(
                'title' => $title,
            ));
        }
        if(!empty($order)){
            $form->populate(array(
                'order' => $order,
            ));
        }
        
    if ($this->getRequest()->isPost()) {
      $fvalues = $form->getValues();
      if($fvalues['form_search'] == 'form_search'){
            $this->view->title = $fvalues['title'];
            $this->view->order = $fvalues['order'];
        }
        //echo $select; die;
        //$select = $table->select();
    }
    $table = Engine_Api::_()->getDbTable('tvs','tv');
    $select = $table->select();
    if(!empty($title)){
        $select->where('title like ?',$title);
    }
    if(!empty($order)){
        if($order == '1')
            $select->order('modified_date DESC');
        else   
            $select->order('view_count DESC');
    }
//    echo $select; die;
    $page = $this->_getParam('page', 1);
    $this->view->paginator = $paginator = Zend_Paginator::factory($select);   
    $this->view->paginator->setItemCountPerPage(25);
    $this->view->paginator->setCurrentPageNumber($page);
  }

  
}